
(function ($) {
    var Defaults = function () {};
    $.extend(Defaults.prototype, {
        yes: "Yes",
        no: "No",
        title: "Confirmation Required",
        msg: "Do you wish to proceed?"
    });
    
    $.confirmDialog = function (options, callbackYes,callbackNo) {
        // Pass the options and a callback to execute if affirmative user
        // response.
        var opts = new Defaults();
        $.extend(opts, options);
        
        var exit_status = 0;
    
        var yesFunc = function () {
            exit_status = 1;
            $(this).dialog('close');
        }
        var noFunc = function () {
            exit_status = 0;
            $(this).dialog('close');
        }
        
        var dlg = $('body').append("<div></div>").find('div:last')
                .dialog({
                    autoOpen: false,
                    modal: true,
					focus:function(){
						$(document).off("keydown");
					},
                    close: function () {
                        // Clean up
                        dlg.dialog("destroy").remove();
                    }
            });
        
        // Set options, open, and bind callback
        var buttons = new Object();
        buttons[opts.yes] = yesFunc;
        buttons[opts.no] = noFunc;
        dlg.dialog('option', 'title', opts.title);
        dlg.dialog('option', 'buttons', buttons);
        dlg.text(opts.msg ? opts.msg : "&nbsp;").dialog('open')
            .one('dialogclose', function () {
                if (exit_status) {
                    callbackYes();
                }
				else if(callbackNo!=null)
				{
					callbackNo();
				}
        });
    }
    
    $.confirmDialog.defaults = function (options) {
        $.extend(Defaults.prototype, options);
    }
    
})(jQuery);
